package br.com.clubelivro.modelo;

import gov.sefaz.utils.entidade.EntidadeBase;

import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.SequenceGenerator;
import javax.validation.constraints.NotNull;

@Entity

@NamedQueries({
	@NamedQuery(name="Pagamento.buscarTodos", query="select obj from Pagamento obj order by obj.data"),
	@NamedQuery(name="Pagamento.buscarPorSocio", query="select obj from Pagamento obj where obj.socio.id =:p0 order by obj.data"),
	@NamedQuery(name="Pagamento.buscarPorMesAno", query="select obj from Pagamento obj where obj.mes =:p0 and obj.ano =:p1 order by obj.data"),
	@NamedQuery(name="Pagamento.countPorSocioMesAno", query="select count(obj.id) from Pagamento obj where obj.socio.id =:p0 and obj.mes =:p1 and obj.ano =:p2")
})
public class Pagamento extends EntidadeBase {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Id
	@SequenceGenerator(name="pagamento_seq", sequenceName="pagamento_sequence")
	@GeneratedValue(strategy=GenerationType.AUTO, generator="pagamento_seq")
	private Long id;
	
	private Date data;
	
	private BigDecimal valor;
	
	private Integer mes;
	
	private Integer ano;
	
	@NotNull(message="Obrigatório informar o sócio!")
	@ManyToOne
	@JoinColumn(name="id_socio")
	private Socio socio;
	
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Date getData() {
		return data;
	}

	public void setData(Date data) {
		this.data = data;
	}

	public BigDecimal getValor() {
		return valor;
	}

	public void setValor(BigDecimal valor) {
		this.valor = valor;
	}

	public Integer getMes() {
		return mes;
	}

	public void setMes(Integer mes) {
		this.mes = mes;
	}

	public Integer getAno() {
		return ano;
	}

	public void setAno(Integer ano) {
		this.ano = ano;
	}

	public Socio getSocio() {
		return socio;
	}

	public void setSocio(Socio socio) {
		this.socio = socio;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Pagamento other = (Pagamento) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}
}
